package cn.icen.activity.utils;

import java.util.ArrayList;

import cn.icen.activity.model.FileItem;
import cn.lyf.icen.R;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BookAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<FileItem> mFileList;
	private LayoutInflater mLayoutInflater;
	private int mCount;
	
	public BookAdapter(Context c, ArrayList<FileItem> fileList){
		mContext = c;
		mFileList = fileList;
		mLayoutInflater = LayoutInflater.from(c);
		mCount = mFileList.size();
	}
	public int getCount() {
		// TODO Auto-generated method stub
		return mCount;
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater li = mLayoutInflater;
		Context context = mContext;
		convertView = li.inflate(R.layout.book_item_layout, null);
		TextView tv = (TextView)convertView.findViewById(R.id.book_item_title);
		FileItem item = mFileList.get(position);
		tv.setText(item.getFileName());
		Drawable bottom;
		if(item.getDirFlag())
			bottom = context.getResources().getDrawable(R.drawable.phone_book_fload);
		else
			bottom = context.getResources().getDrawable(R.drawable.phone_book_file);
		
		tv.setCompoundDrawablesWithIntrinsicBounds(null, bottom, null, null);

		
		return convertView;
	}

}
